package model

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone     string `gorm:"type:char(11)" json:"phone"`
	Password  string `gorm:"type:char(32)" json:"password"`
	NickName  string `gorm:"type:varchar(30)" json:"nickName"`
	AvatarUrl string `gorm:"type:varchar(255)" json:"avatarUrl"`
	Refer     string `gorm:"type:varchar(100)" json:"refer"`
}

func (u *User) IsUser(db *gorm.DB, phone string) error {
	return db.Where("phone = ?", phone).First(&u).Error
}
func (u *User) Register(db *gorm.DB) error {
	return db.Create(&u).Error
}

func (u *User) GetUser(db *gorm.DB, userId int) error {
	return db.Where("id = ?", userId).First(&u).Error
}
